Skip to content

fix: gate xblock action menu on authz edit/manage_tags permissions - #39050

Open
jacobo-dominguez-wgu wants to merge 2 commits into
openedx:masterfrom
WGU-Open-edX:course-editor-content
Open

jacobo-dominguez-wgu wants to merge 2 commits into
openedx:masterfrom
WGU-Open-edX:course-editor-content

Conversation

@jacobo-dominguez-wgu

@jacobo-dominguez-wgu jacobo-dominguez-wgu commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description

This change fixes how the Studio XBlock component card ("header actions" menu) decides which authoring affordances to show when the AuthZ course-authoring rollout (authz.enable_course_authoring) is enabled, and simplifies how those decisions reach the template.

Problems fixed

  1. Legacy access was validated even when AuthZ was enabled. can_edit was derived from has_studio_write_access(...) OR'd with the AuthZ result, so legacy studio write access was always honored — even on a course where AuthZ is enabled and denies the user. user_has_course_permission(...) already encapsulates the correct logic (AuthZ-only when the flag is on, legacy fallback when off), so the extra legacy check was both redundant and wrong.

  2. "Manage Tags" was unreachable for a tags-only role. The gating flags were plumbed through the template as separate is_authz_authoring_enabled / authz_can_edit_course_content / authz_can_manage_tags values, and the "Manage Tags" item was nested under a condition tied to edit access. A role granted only courses.manage_tags(no edit) could not reach it. The div now opens on can_edit or can_manage_tags or can_edit_title`.

  3. Edit-type actions would leak to a tags-only user. Opening the menu for a tags-only user exposes the edit-type items inside (Move, Manage Access, Copy to Clipboard, Duplicate, Delete), which were gated on flags that did not account for can_edit.

  4. can_edit_title was hardcoded True. The div-open condition references can_edit_title, which was always True, so the div rendered regardless of permissions.

Supporting information

Fixes openedx/openedx-authz#418

Testing instructions

Automated:

  • Run the regression tests added in TestXBlockViewHandlerHeaderActionsAuthz:

    DJANGO_SETTINGS_MODULE=cms.envs.test uv run python -m pytest \
      "cms/djangoapps/contentstore/views/tests/test_block.py::TestXBlockViewHandlerHeaderActionsAuthz" -p no:randomly
    

    They cover the component edit button on a leaf html component preview:

    • authz flag on + edit_course_content granted + no legacy write access → edit button shown
    • authz flag on + permission denied + no legacy write access → edit button hidden

Manual:

Prerequisite: a course with authz.enable_course_authoring enabled and roles that grant granular permissions (courses.edit_course_content,courses.manage_tags).

  1. Editor role (has edit_course_content and no manage_tags): open a unit in Studio. The component card action menu shows Edit, Manage Access, Move, Copy to Clipboard, Duplicate, Delete, and no Manage Tags.
  2. Read-only role (neither permission): open a unit. The header-actions menu does not render at all.
  3. Flag off (course not on the rollout): behavior is unchanged — an author with legacy studio write access sees all actions.
  4. . Tags-only role (manage_tags, and edit_course_content): open a unit. The action menu is reachable and shows Manage Tags.

Demo

User with edit_course_content permission must be able to edit course content.

Screen.Recording.2026-08-31.at.3.16.16.PM.mov

AI usage notice

Used Copilot with auto model mode (Claude) to assist on the modification and creation of unit tests.

Important

Needs to be reviewed after #39013, it contains code from that pr.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Aug 31, 2026
@openedx-webhooks

openedx-webhooks commented Aug 31, 2026

Copy link
Copy Markdown

Thanks for the pull request, @jacobo-dominguez-wgu!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Aug 31, 2026
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Sep 2, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Sep 2, 2026
@jacobo-dominguez-wgu
jacobo-dominguez-wgu marked this pull request as ready for review September 7, 2026 18:05

@carlos-marquez-wgu carlos-marquez-wgu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and working locally

@BryanttV BryanttV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +260 to +263
can_edit = has_studio_write_access(request.user, usage_key.course_key) or (
is_authz_authoring_enabled and authz_can_edit_course_content
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this or is that legacy permissions are always being validated even if AuthZ is enabled, and we don't want that.

And now that I'm checking the code again, one suggestion to simplify this further: is_authz_authoring_enabled doesn't need to reach the template at all.

can_edit and can_manage_tags could each resolve their own "flag is off" default internally (e.g. can_edit delegating entirely to user_has_course_permission(..., legacy_permission=WRITE), and the tags check returning True when the flag is off, since tag management has no legacy-permission concept). That way only two already-final booleans (can_edit, can_manage_tags) need to reach studio_xblock_wrapper.html.

This also fixes another bug: "Manage Tags" is nested inside the div gated on edit_course_content, so a role granted only manage_tags (no edit access) could never reach it. The div should open on can_edit or can_manage_tags instead.

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @BryanttV! Refactored so only the two already-final booleans reach the template.

Two follow-ups worth flagging that came out of this:

  • Once the div opens for a manage-tags-only user, the edit-type items inside (Move, Manage Access, Copy, Duplicate, Delete) were gated on flags that didn't account for can_edit, so they'd leak. Gated those on can_edit at the source (can_add/can_move now and can_edit; Copy on is_course and can_edit), matching how can_edit_visibility already worked.

  • The div gate also references can_edit_title, which was hardcoded True, so the div always rendered. Made can_edit_title permission-aware too: True when the flag is off, else courses.edit_course_content.

Comment thread cms/djangoapps/contentstore/views/tests/test_block.py Outdated
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the course-editor-content branch 2 times, most recently from 46a3067 to fd9f9bc Compare September 17, 2026 16:33

@BryanttV BryanttV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these changes, the code looks much better! LGTM. Could we update the cover letter to reflect what was done?

@jacobo-dominguez-wgu jacobo-dominguez-wgu changed the title grant xblock edit access via authz edit_course_content permission fix: gate xblock action menu on authz edit/manage_tags permissions Sep 17, 2026
@jacobo-dominguez-wgu

Copy link
Copy Markdown
Contributor Author

Thanks for making these changes, the code looks much better! LGTM. Could we update the cover letter to reflect what was done?

Done, thanks!

@mariajgrimaldi mariajgrimaldi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments :)

Thanks!

Comment thread cms/djangoapps/contentstore/views/tests/test_block.py Outdated
Comment on lines +164 to +165
if not enable_authz_course_authoring(course_key):
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we move this condition (legacy permission = None AND flag off) to user_has_course_permission? So we don't have to check this twice when the flag is on?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved it to user_has_course_permission by adding a default_fallback prop, also added new test to cover it, thanks!

@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the course-editor-content branch 2 times, most recently from 0f6a2af to 46a3067 Compare September 22, 2026 17:54
Centralize the "flag off + no legacy permission" default in user_has_course_permission so _user_can_manage_tags and _user_can_edit_title don't repeat the flag check. Add tests for the new parameter and switch two test asserts to plain asserts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Course Editor is not allowed to edit the component's content just the title

6 participants